package homework;
import java.util.Random;
import java.util.Scanner;

public class day06 {
    public static void main(String[] args) {
        say();
        System.out.println("-----");
        say("haha");
        System.out.println("-----");
        say("heihei","22");
        System.out.println("-----");
        int b =sum(5,6);
        System.out.println(b);
        int n=5,m=6;
        int c=sum(n,m);
        System.out.println(c);
        System.out.println("-----");
        int[] d = generateArray(5,100);
        System.out.println("数组长度为:"+d.length);
        for (int i =0;i<d.length;i++){
            System.out.println(d[i]);
        }
        int[] f =generateArray(10,50);
        System.out.println("第一个元素的值:"+f[0]);
        for (int i=0;i<f.length;i++){
            System.out.println(f[i]);
        }
        System.out.println("-----");
        //平均分
       double[] scores = inputData(6);
       double avg = calAvg(scores);
        System.out.println("平均分:"+avg);
        System.out.println("-----");
        //猜数字
        Scanner scan = new Scanner(System.in);
        Random rand = new Random();
        int num =rand.nextInt(1000)+1;
        System.out.println(num);
        while (true){
            System.out.println("猜吧!");
            int guess = scan.nextInt();
            if (guess>num){
                System.out.println("猜大了");
            }else if (guess<num){
                System.out.println("猜小了");
            }else{
                System.out.println("恭喜你猜对了");
                break;
            }

        }
    }





    //generateArray
    public static int[] generateArray (int len,int max){
        Random rand = new Random();
        int[] arr = new int[len];
        for (int i=0;i<arr.length;i++){
        arr[i] = rand.nextInt(max+1);
        }
        return arr;
    }
    //录入n位评委的评分
    public static double[] inputData(int n){
        double[] scores =new double[n];//定义了一个浮点数组类型为scores
        Scanner scan = new Scanner(System.in);
        for (int i=0;i<scores.length;i++){
            System.out.println("请输入第"+(i+1)+"位评委的评分");
            scores[i] = scan.nextDouble();
        }
        return scores;
    }
    //j计算平均分
   public static double calAvg(double[] scores){//第1步
        double total = 0.0;//第2步
        double max =scores[0];//第5步
        double min = scores[0];//7
        for (int i=0;i<scores.length;i++){//第3步
            total = total+scores[i];//第4步
            if (scores[i]>max){//第6步
                max = scores[i];
            }
            if (scores[i]<min){//8
              min = scores[i];
            }
        }
        double avg = (total-max-min)/(scores.length-2);//9
        return avg;//10
   }
    //无参无返回值
    public static void say(){
        System.out.println("大家好,我叫哈哈,今年20岁了");
    }
    //有一个参无返回值
    public static void say(String name){
        System.out.println("大家好,我叫"+name+",今年21岁了");
    }
    //有两个参无返回值
    public static void say(String name,String age){
        System.out.println("大家好,我叫"+name+",今年"+age+"岁了");
    }
    //sum
    public static int sum(int num1,int num2){
        int num = num1+num2;
        return num;
    }




}
